package com.xqb.modules.controller.exam;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.ExaUserAnswers;
import com.xqb.modules.service.IExaUserAnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户答题Controller
 *
 * @author ruoyi
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/exam/userAnswers")
public class ExaUserAnswersController extends BaseController {
    @Autowired
    private IExaUserAnswersService exaUserAnswersService;

    /**
     * 查询用户答题列表
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExaUserAnswers exaUserAnswers) {
        startPage();
        List<ExaUserAnswers> list = exaUserAnswersService.selectExaUserAnswersList(exaUserAnswers);
        return getDataTable(list);
    }

    /**
     * 导出用户答题列表
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:export')")
    @Log(title = "用户答题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExaUserAnswers exaUserAnswers) {
        List<ExaUserAnswers> list = exaUserAnswersService.selectExaUserAnswersList(exaUserAnswers);
        ExcelUtil<ExaUserAnswers> util = new ExcelUtil<ExaUserAnswers>(ExaUserAnswers.class);
        util.exportExcel(response, list, "用户答题数据");
    }

    /**
     * 获取用户答题详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exaUserAnswersService.selectExaUserAnswersById(id));
    }

    /**
     * 新增用户答题
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:add')")
    @Log(title = "用户答题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExaUserAnswers exaUserAnswers) {
        return toAjax(exaUserAnswersService.insertExaUserAnswers(exaUserAnswers));
    }

    /**
     * 修改用户答题
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:edit')")
    @Log(title = "用户答题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExaUserAnswers exaUserAnswers) {
        return toAjax(exaUserAnswersService.updateExaUserAnswers(exaUserAnswers));
    }

    /**
     * 删除用户答题
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:remove')")
    @Log(title = "用户答题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exaUserAnswersService.deleteExaUserAnswersByIds(ids));
    }

    /**
     * 批量新增用户答题
     */
    @PreAuthorize("@ss.hasPermi('exam:userAnswers:add')")
    @Log(title = "用户答题", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<ExaUserAnswers> exaUserAnswers) {
        return toAjax(exaUserAnswersService.insertExaUserAnswersList(exaUserAnswers));
    }
}
